<div th:fragment="fwb-modal">
<meta charset="UTF-8" />
<meta http-equiv="pragma" content="no-cache"></meta>
<meta http-equiv="cache-control" content="no-cache"></meta>
<meta http-equiv="expires" content="0"></meta>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body{
	padding: 0px 10px;
}
button{
	width:97px;
	background: #3399FF!important;
}
</style>
<script type="text/javascript">
var selection = []; //保存选中服务项 
function queryForm() {
	$("#dgForm").bootstrapTable("refresh");
}

/**服务包信息数据*/
function initFwbTable() {
	$("#dgForm").bootstrapTable({
		idField : "FWBID",
		striped : true,
		toolbar : "#dgFormToolbar",
		columns : [
			{
				field: "checkStatus",
				checkbox: true
			},       
			{
				field : "FWBID",
				title : "服务包编码"
			},
			{
				field : "FWBMC",
				title : "服务包名称"
			},
			
			{
				field : "YLJGMC",
				title : "所属机构"
			},
			{
				field : "YXQ",
				title : "有效期",
				formatter : function(value, row, index){
					return getYxq(value);
				}
			},
			{
				field : "FY",
				title : "服务包费用",
			},
			{
				field : "FWBZT",
				title : "状态",
				formatter : function(value, row, index){
					return getFwzt(value);
				}
			},
			{
				field : "CJSJ",
				title : "创建日期",
				formatter : function(value, row, index){
					if(!StringUtils.isEmpty(value)){
						value = value.substr(0, 10);
					}
					return value;
				}
			}
		]
		,pagination : true
		,contentType: "application/x-www-form-urlencoded; charset=UTF-8"
		,sidePagination: "server"
		,pageNumber: 1
		,pageSize: 10
		,method : "post"
		,responseHandler:responseHandler //在渲染页面数据之前执行的方法，此配置很重要!!!!!!! 
		,url: contextRoot+"fwb/"
		,queryParams: function(params){
			//params["FWBMC"] = $("#FWBMC").val();
			params["YLJGID"] = "7D7513CE-30A4-11E7-BFE3-00163E0E1CC6";
			params["YLJGID"] = $("#YLJGID").val();
			params["FWBZT"] = $("#FWBZT").val();
			return params;
		}
		,queryParamsType: "",
		onClickRow : function(row, e, field){
			$(e).addClass("changetr");
			$(e).siblings("tr").removeClass("changetr");
			$("#enter").data("info", row);
		}
	});
	SelectCheckBox();
}


/**获取服务状态*/
function getFwzt(fwbzt){
	if(fwbzt == "0"){
		fwbzt = "停用";
	}
	else if(fwbzt == "1"){
		fwbzt = "启用";
	}
	return fwbzt;
}

/**获取有效期*/
function getYxq(yxq){
	if(yxq == "01"){
		yxq = "一个月";
	}
	else if(yxq == "02"){
		yxq = "三个月";
	}
	else if(yxq == "03"){
		yxq = "半年";
	}
	else if(yxq == "04"){
		yxq = "一年";
	}
	return yxq;
}

/**操作格式化*/
function operateFormatter(value, row, index) {
	return $("#tableToolBar").html();
}

/**查询按钮点击回调*/
function btnQueryHandler() {
	queryForm();
}

/**校验是否选中服务包*/
function validate(info){
	if(StringUtils.isEmpty(info)){
		return false;
	}else{
		return true;
	}
}

/**选中方法*/
function SelectCheckBox(){
		 //选中事件操作数组 
		 var union = function(array,fws){ 
			$.each(fws, function (i, fw) { 
				 if(!objInArray(fw, array)){ 
				 	array[array.length] = fw; 
				 } 
			 }); 
			 return array; 
		 }; 
		 //取消选中事件操作数组 
		 var difference = function(array,fws){ 
			 $.each(fws, function (i, fw) { 
				 if(objInArray(fw, array)){ 
				 	array.splice(index, 1); 
				 } 
			 }); 
			 return array; 
		 }; 
		 var _ = {"union":union,"difference":difference}; 
		 //绑定选中事件、取消事件、全部选中、全部取消 
		 $("#dgForm").on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", function (e, rows) { 
			var fws = $.map(!$.isArray(rows) ? [rows] : rows, function (row) { 
				delete row["checkStatus"]
		   		return row; 
		  	}); 
		  	func = $.inArray(e.type, ["check", "check-all"]) > -1 ? "union" : "difference"; 
		  	selection = _[func](selection, fws); 
		 }); 
}

//表格分页之前处理多选框数据 
function responseHandler(res) {
	$.each(res.rows, function (i, row) { 
 		row.checkStatus = objInArray(row, selection); //判断当前行的数据id是否存在与选中的数组，存在则将多选框状态变为true 
	}); 
	return res; 
}

/**判断数组中是否有对象*/
function objInArray(obj, array){
	var flag = false;
	for ( var i in array) {
		if(array[i]["FWBID"] == obj["FWBID"]){
			flag = true;
			break;
		}
	}
	return flag;
}

</script>
<script type="text/html" id="fwbModal">
<!-- 模态框（Modal）-->
<div class="modal fade" id="myModal" style="height: 100%;" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width:60%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">服务包信息列表</h4>
            </div>
            <div class="modal-body">
					<div id="dgFormToolbar">
						<div class="form-inline">
							<div class="form-group">
								<input id="FWBMC" name="FWBMC" class="form-control" type="text"
									placeholder="服务包名称">
								<input class="yljgid" name="YLJGID" style="display: none;">
							</div>
							<button id="btnQuery" class="btn btn-default" type="button"
								onclick="btnQueryHandler()">查询</button>
						</div>
					</div>
					<table id="dgForm">
					</table>
			</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal" id="back">返回</button>
                <button type="button" class="btn btn-primary" id="enter">确认</button>
            </div>
        </div>
    </div>
</div> 
</script>
<script type="text/html" id="tableToolBarStart">
<a class="detail tableToolBarBtn" href="javascript:void(0)" title="详细">详细</a>
</script>
<script type="text/html" id="tableToolBarStop">
<a class="detail tableToolBarBtn" href="javascript:void(0)" title="详细">详细</a>
</script>